﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using MaxStudio.Concrete.Web;
using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server;
using MaxStudio.Concrete.Server.Service;
using MaxStudio.Concrete.Server.Dao;
using System.Configuration;

namespace MaxStudio.Concrete.Web.Pages
{
    public partial class RPTMixProportionDesign : BasePage
    {
        string wholSequence = "LT-12-01";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindGridView();
            }
        }
        #region Private Method

        private void BindGridView()
        {
            RPTMixProportionDesignService RPTMixProportionDesignServiceObj = ServiceFactory.getRPTMixProportionDesignService();
            OperationResult<List<tb_RPT_MixProportionDesign>> result = RPTMixProportionDesignServiceObj.GetAllMixProportionDesign();

            if (result.operationSuccess)
            {
                gvRPTMixProportionDesignList.DataSource = result.obj;
                gvRPTMixProportionDesignList.DataBind();
            }
            else
            {
                //EXCEPTION
                //return null;
            }
        }

        private void BindEdieDialog(int id)
        {
            RPTMixProportionDesignService RPTMixProportionDesignServiceObj = ServiceFactory.getRPTMixProportionDesignService();
            OperationResult<tb_RPT_MixProportionDesign> resultEdit = RPTMixProportionDesignServiceObj.GetMixProportionDesignById(id);

            if (resultEdit.operationSuccess == true)
            {
                txtEditProjectName.Text = resultEdit.obj.ProjectName;
                txtEditStrengthGrade.Text = resultEdit.obj.StrengthGrade;
                txtEditTeststrength.Text = resultEdit.obj.Teststrength;
                txtEditDemandSlump.Text = resultEdit.obj.DemandSlump;
                txtEditSampleName.Text = resultEdit.obj.SampleName;
                txtEditDesignDate.Text = resultEdit.obj.DesignDate;
                txtEditCementManufacturers.Text = resultEdit.obj.CementManufacturers;
                txtEditAdmixtureName.Text = resultEdit.obj.AdmixtureName;
                txtEditStonesOriginTypes.Text = resultEdit.obj.StonesOriginTypes;
                txtEditAdmixtureNameModel.Text = resultEdit.obj.AdmixtureNameModel;
                txtEditCementFactoryDate.Text = resultEdit.obj.CementFactoryDate;
                txtEditAshManufacturer.Text = resultEdit.obj.AshManufacturer;
                txtEditStonesNominalSize.Text = resultEdit.obj.StonesNominalSize;
                txtEditAdmixtureManufacturer.Text = resultEdit.obj.AdmixtureManufacturer;
                txtEditCementVarietiesLab.Text = resultEdit.obj.CementVarietiesLab;
                txtEditSandProducingArea.Text = resultEdit.obj.SandProducingArea;
                txtEditAdmixtureMixedQuantity.Text = resultEdit.obj.AdmixtureMixedQuantity;
                txtEditAdmixture.Text = resultEdit.obj.Admixture;
                txtEditProductStrengthGrade.Text = resultEdit.obj.ProductStrengthGrade;
                txtEditProductWaterBinderRatio.Text = resultEdit.obj.ProductWaterBinderRatio;
                txtEditProductSlump.Text = resultEdit.obj.ProductSlump;
                txtEditCementPerM.Text = resultEdit.obj.CementPerM;
                txtEditSandPerM.Text = resultEdit.obj.SandPerM;
                txtEditGravelPerM.Text = resultEdit.obj.GravelPerM;
                txtEditWaterPerM.Text = resultEdit.obj.WaterPerM;
                txtEditAdmixturePerM.Text = resultEdit.obj.AdmixturePerM;
                txtEditAdditivePerM.Text = resultEdit.obj.AdditivePerM;
                txtEditExpansionAgentPerM.Text = resultEdit.obj.ExpansionAgentPerM;
                txtEditFiberPerM.Text = resultEdit.obj.FiberPerM;
                txtEditTestStandard.Text = resultEdit.obj.TestStandard;
                txtEditRemark.Text = resultEdit.obj.Remark;
                txtEditApproval.Text = resultEdit.obj.Approval;
                txtEditDesign.Text = resultEdit.obj.Design;
                txtEditTest.Text = resultEdit.obj.Test;

                lbLastModier.Text = "TEST";
                lbEidtId.Text = resultEdit.obj.Id.ToString();
                lbLastModifyDate.Text = resultEdit.obj.ModifyDate.ToShortDateString();
            }
        }

        private void DeleteRecords(int id)
        {
            lbDeleteId.Text = id.ToString();
        }

        #endregion

        #region Event
       
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            RPTMixProportionDesignService RPTMixProportionDesignServiceObj = ServiceFactory.getRPTMixProportionDesignService();
            tb_RPT_MixProportionDesign instance = new tb_RPT_MixProportionDesign();

            instance.Sequence = wholSequence;
            instance.ProjectName = txtProjectName.Text;
            instance.StrengthGrade = txtStrengthGrade.Text;
            instance.Teststrength = txtTeststrength.Text;
            instance.DemandSlump = txtDemandSlump.Text;
            instance.SampleName = txtSampleName.Text;
            instance.DesignDate = txtDesignDate.Text;
            instance.CementManufacturers = txtCementManufacturers.Text;
            instance.AdmixtureName = txtAdmixtureName.Text;
            instance.StonesOriginTypes = txtStonesOriginTypes.Text;
            instance.AdmixtureNameModel = txtAdmixtureNameModel.Text;
            instance.CementFactoryDate = txtCementFactoryDate.Text;
            instance.AshManufacturer = txtAshManufacturer.Text;
            instance.StonesNominalSize = txtStonesNominalSize.Text;
            instance.AdmixtureManufacturer = txtAdmixtureManufacturer.Text;
            instance.CementVarietiesLab = txtCementVarietiesLab.Text;
            instance.SandProducingArea = txtSandProducingArea.Text;
            instance.AdmixtureMixedQuantity = txtAdmixtureMixedQuantity.Text;
            instance.Admixture = txtAdmixture.Text;
            instance.ProductStrengthGrade = txtProductStrengthGrade.Text;
            instance.ProductWaterBinderRatio = txtProductWaterBinderRatio.Text;
            instance.ProductSlump = txtProductSlump.Text;
            instance.CementPerM = txtCementPerM.Text;
            instance.SandPerM = txtSandPerM.Text;
            instance.GravelPerM = txtGravelPerM.Text;
            instance.WaterPerM = txtWaterPerM.Text;
            instance.AdmixturePerM = txtAdmixturePerM.Text;
            instance.AdditivePerM = txtAdditivePerM.Text;
            instance.ExpansionAgentPerM = txtExpansionAgentPerM.Text;
            instance.FiberPerM = txtFiberPerM.Text;
            instance.TestStandard = txtTestStandard.Text;
            instance.Remark = txtRemark.Text;
            instance.Approval = txtApproval.Text;
            instance.Design = txtDesign.Text;
            instance.Test = txtTest.Text;

            OperationResult<tb_RPT_MixProportionDesign> result = RPTMixProportionDesignServiceObj.CreateMixProportionDesign(instance);
            BindGridView();

        }
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            int editId = 0;
            if (lbEidtId.Text.Length > 0)
            {
                editId = Int32.Parse(lbEidtId.Text);
            }

            RPTMixProportionDesignService RPTMixProportionDesignServiceObj = ServiceFactory.getRPTMixProportionDesignService();
            tb_RPT_MixProportionDesign entity = new tb_RPT_MixProportionDesign();

            entity.Id = editId;
            entity.Sequence = wholSequence;
            entity.ProjectName =txtEditProjectName.Text;
            entity.StrengthGrade =txtEditStrengthGrade.Text;
            entity.Teststrength =txtEditTeststrength.Text;
            entity.DemandSlump =txtEditDemandSlump.Text;
            entity.SampleName =txtEditSampleName.Text;
            entity.DesignDate =txtEditDesignDate.Text;
            entity.CementManufacturers =txtEditCementManufacturers.Text;
            entity.AdmixtureName =txtEditAdmixtureName.Text;
            entity.StonesOriginTypes =txtEditStonesOriginTypes.Text;
            entity.AdmixtureNameModel =txtEditAdmixtureNameModel.Text;
            entity.CementFactoryDate =txtEditCementFactoryDate.Text;
            entity.AshManufacturer =txtEditAshManufacturer.Text;
            entity.StonesNominalSize =txtEditStonesNominalSize.Text;
            entity.AdmixtureManufacturer =txtEditAdmixtureManufacturer.Text;
            entity.CementVarietiesLab =txtEditCementVarietiesLab.Text;
            entity.SandProducingArea =txtEditSandProducingArea.Text;
            entity.AdmixtureMixedQuantity =txtEditAdmixtureMixedQuantity.Text;
            entity.Admixture =txtEditAdmixture.Text;
            entity.ProductStrengthGrade =txtEditProductStrengthGrade.Text;
            entity.ProductWaterBinderRatio =txtEditProductWaterBinderRatio.Text;
            entity.ProductSlump =txtEditProductSlump.Text;
            entity.CementPerM =txtEditCementPerM.Text;
            entity.SandPerM =txtEditSandPerM.Text;
            entity.GravelPerM =txtEditGravelPerM.Text;
            entity.WaterPerM =txtEditWaterPerM.Text;
            entity.AdmixturePerM =txtEditAdmixturePerM.Text;
            entity.AdditivePerM =txtEditAdditivePerM.Text;
            entity.ExpansionAgentPerM =txtEditExpansionAgentPerM.Text;
            entity.FiberPerM =txtEditFiberPerM.Text;
            entity.TestStandard =txtEditTestStandard.Text;
            entity.Remark =txtEditRemark.Text;
            entity.Approval =txtEditApproval.Text;
            entity.Design =txtEditDesign.Text;
            entity.Test =txtEditTest.Text;

            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            entity.CreateDate = DateTime.Now;

            OperationResult<tb_RPT_MixProportionDesign> resultEdit = RPTMixProportionDesignServiceObj.ModifyMixProportionDesign(entity);

            BindGridView();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int deleteId = Int32.Parse(lbDeleteId.Text);
            RPTMixProportionDesignService RPTMixProportionDesignServiceObj = ServiceFactory.getRPTMixProportionDesignService();
            tb_RPT_MixProportionDesign deleteEntity = new tb_RPT_MixProportionDesign();

            deleteEntity.Id = deleteId;
            RPTMixProportionDesignServiceObj.DeleteMixProportionDesign(deleteEntity);

            BindGridView();
        }

        protected void gvRPTMixProportionDesignList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                string strSelectId = e.CommandArgument.ToString();
                BindEdieDialog(Int32.Parse(strSelectId));
            }

            if (e.CommandName == "del")
            {
                string strSelectId = e.CommandArgument.ToString();
                DeleteRecords(Int32.Parse(strSelectId));
            }
        }

        protected void gvRPTMixProportionDesignList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvRPTMixProportionDesignList.PageIndex = e.NewPageIndex;
            BindGridView();
        }
        #endregion
    }
}
